const path = require('path');//引入path模块
function resolve(dir){
    return path.join(__dirname,dir)//path.join(__dirname)设置绝对路径
}
const isProd = process.env.NODE_ENV === 'production'
// 设置cdn 资源
let cdn = {
  css: [
    // element-ui css
    'https://unpkg.com/element-ui/lib/theme-chalk/index.css',// 样式表
    // 富文本框插件样式
    'https://cdn.bootcdn.net/ajax/libs/quill/2.0.0-dev.4/quill.bubble.css'
  ],
  js: [
    // vue must at first!
    'https://unpkg.com/vue/dist/vue.js', // vuejs
    // element-ui js
    'https://unpkg.com/element-ui/lib/index.js', // elementUI
    // 富文本框插件
    'https://cdn.bootcdn.net/ajax/libs/quill/2.0.0-dev.4/quill.js'
  ]
}
var externals = {
  'vue': 'Vue',
  'element-ui': 'ELEMENT',
}
cdn = isProd ? cdn : { css: [], js: [] }
externals = isProd ? externals : {}
module.exports={
    chainWebpack:(config)=>{
        config.resolve.alias
        .set('@',resolve('./src'))
        .set('components',resolve('./src/components'))
        .set('views',resolve('src/views'))
        .set('assets',resolve('src/assets'))
        .set('network',resolve('src/network'))
        .set('common',resolve('src/common'))
        .set('utils',resolve('src/utils'))
        //set第一个参数：设置的别名，第二个参数：设置的路径
        config.when(process.env.NODE_ENV === 'production', config => {
          config.entry('app').clear().add('./src/main-prod.js')
        })
        // 开发模式
        config.when(process.env.NODE_ENV === 'development', config => {
            config.entry('app').clear().add('./src/main-dev.js') 
        })
        config.plugin('html').tap(args => {
          args[0].cdn = cdn
          return args
        })
    },
    pluginOptions: { // 第三方插件配置
        'style-resources-loader': {
          preProcessor: 'less'
          // less所在文件路径
        }
      },
      configureWebpack: {
        externals
    },
      devServer: {
        open: true, 
      }

}
